package com.maltys.dp;

/**
 * ⼀个机器⼈位于⼀个 m x n ⽹格的左上⻆ （起始点在下图中标记为 “Start” ）。
 * 机器⼈每次只能向下或者向右移动⼀步。机器⼈试图达到⽹格的右下⻆（在下图中标记为 “Finish” ）。
 * 问总共有多少条不同的路径？
 *
 * @author malty
 * @link <a href="https://leetcode.cn/problems/unique-paths/description/">不同路径</a>
 */
public class DifferentPath {
    public static void main(String[] args) {
        DifferentPath differentPath = new DifferentPath();
        int difference = differentPath.uniquePaths(3,7);
        System.out.println(difference);
    }

    public int uniquePaths(int m,int n) {
        int[][] matrix = new int[m][n];
        for (int i = 1; i < n; i++) {
            matrix[0][i] = 1;
        }
        for (int i = 1; i < m; i++) {
            matrix[i][0] =  1;
        }
        for (int i = 1; i < m; i++) {
            for (int j = 1; j < n; j++) {
                matrix[i][j] = matrix[i - 1][j] + matrix[i][j - 1];
            }
        }
        return matrix[m - 1][n - 1];
    }
}
